package listbyorder.access001_100.test66;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/3 19:53
 */
public class Solution1 {

    public int[] plusOne(int[] digits) {
        int len = digits.length;
        if (digits[len - 1] < 9) {
            digits[len - 1]++;
            return digits;
        }
        int index = len - 1;
        while (index >= 0) {
            if (digits[index] != 9) {
                digits[index]++;
                break;
            }
            digits[index--] = 0;
        }
        if (index < 0) {
            int[] res = new int[len + 1];
            res[0] = 1;
            return res;
        }
        return digits;
    }
}
